<!-- 延时组件 -->
<template>
	<view class="delayTime">
		<!-- 选择加时时长 -->
		<u-picker keyName="label" itemHeight="80" visibleItemCount="8" :columns="addTimeData"
			:closeOnClickOverlay="true" :show="show" @confirm="addTimeConfirm" @cancel="addTimeClose"
			@close="addTimeClose"></u-picker>

		<PayMode :show="typeShow" @close="typeShowClose" @submit="payModeSubmit"></PayMode>

	</view>
</template>

<script>
	//页面组件
	import PayMode from './payMode.vue'

	// 公共方法
	import {
		wxPayment
	} from '@/utils/wx/wxPublick-h5.js'


	//请求api
	import {
		postOrderAddHourApi, // 延时接口
	} from '@/api/order.js'

	export default {
		props: {
			// 是否显示时间选择
			show: {
				type: Boolean,
				default: false
			},

			// 订单号
			orderNo: {
				type: Number,
				default: 0
			},

			//延时单位
			unit: {
				type: String,
				default: '时'
			},

			// 关闭弹窗
			close: {
				type: Function,
				default: () => {}
			},

			//刷新页面
			locationReload: {
				type: Function,
				default: () => {}
			}
		},
		components: {
			PayMode
		},
		data() {
			return {
				// 加时选择
				addTimeData: [],

				addTimeParams: {
					orderNo: '', //订单号
					duration: '', // 时长
					payType: '', // 支付方式
				},

				//续时支付方式弹窗
				typeShow: false,
			};
		},
		methods: {
			/**
			 * 延时选择时间确定
			 */
			addTimeConfirm(e) {
				// 时间赋值
				this.addTimeParams.duration = e.value[0].value

				// 关闭延时弹窗
				this.addTimeClose()

				// 打开支付方式
				this.typeShow = true
			},

			/**
			 * 关闭延时弹窗
			 */
			addTimeClose() {
				this.$emit('close')
			},

			/**
			 * 关闭支付方式弹窗
			 */
			typeShowClose() {
				this.typeShow = false
			},


			/**
			 * 确认支付方式
			 */
			async payModeSubmit(val) {

				this.addTimeParams.payType = val

				let params = {
					...this.addTimeParams
				}
				console.log(params, '看看选择值');

				let res = await postOrderAddHourApi(params)

				if (res.code !== 200) {
					return uni.showToast({
						title: res.msg,
						duration: 2000,
						icon: 'none'
					})
				}
				this.$emit('locationReload')

				// #ifdef H5
					wxPayment(res.data.result.jsConfig)
				// #endif
			},



		},

		watch: {

			// 单位传入时初始化选择内容
			unit(val) {
				console.log(val, 'unit', this.unit);
				let s1 = []

				if (this.unit === '天8时') {
					for (let i = 1; i < 5; i++) {
						s1.push({
							label: i + '天8时',
							value: i
						})
					}
				} else if (this.unit === '天') {
					for (let i = 1; i < 6; i++) {
						s1.push({
							label: i + '天',
							value: i
						})
					}
				} else {
					for (let i = 1; i < 9; i++) {
						s1.push({
							label: i + '小时',
							value: i
						})
					}
				}

				this.addTimeData.push(s1)

				console.log(this.addTimeData, '看看时间');

			},


			// 订单id传入时存储订单id
			orderNo(val) {
				this.addTimeParams.orderNo = this.orderNo

				console.log(this.addTimeParams, 'kkkkk');
			}
		}
	}
</script>

<style lang="less" scoped>




</style>